<?php

class CategoryController extends Controller
{

    public function actionView()
    {	
	$name = Yii::app()->request->getParam('name');
	if (!$name) {
	    throw new CHttpException(404, 'Нету записи');
	}

	$model = FactoryService::get('category')->getByName($name);
	if (!$model) {
	    throw new CHttpException(404, 'Нету записи');
	}
	$page = Yii::app()->getRequest()->getParam('page', 1);

	$reviews = FactoryService::get('review')->getReviewListByCategory($model, $page);
	
	$pager = new CPagination(FactoryService::get('review')->getReviewCountByCategory($model));
	$pager->setPageSize(Yii::app()->params['perPage']);


	$this->breadcrumbs = array(
	    'Категории' => array('/categories'),
	    $model->getDbData('title')
	);
	SeoManager::getInstance()->set(array(
	    'title' => 'Отзывы категории ' . $model->getDbData('title'),
	    'description' => 'Отзывы в категории ' . $model->getDbData('title'),
	    'keywords' => 'Отзывы в категории ' . $model->getDbData('title'),
	));

	$this->render('view', array(
	    'model' => $model, 'reviews' => $reviews, 'pager' => $pager
		)
	);
    }

    public function actionIndex()
    {
	$this->breadcrumbs = array(
	    'Категории'
	);
	$this->render('index', array(
	    'categories' => FactoryService::get('category')->getCategoryTree()
		)
	);
    }

}

?>
